<!DOCTYPE html>
<html lang="en">
<head>
    <title>录入汇票信息</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/dist/plugins/select2/select2.min.css">
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=86e2297f">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=222aea35">
    <style type="text/css">
        .leftFilter {
            float: left;
            text-align: left;
            margin-right: 5px;
        }

        .clickable {
            color: #489EF1;;
            cursor: pointer;
            text-align: left;
            font-weight: bold;
        }

        .td {
            text-align: center;
        }
    </style>
</head>
<body>
<section class="content" id="list">
    <table class="table table-bordered" style="max-width: 750px;margin: -1px 0">
        <tbody>
        <tr>
            <td class="td-title">出票人</td>
            <td class="td-value">
                <input v-model="jsonData.drawerName" style="width: 100%;border: none" />
            </td>
            <td class="td-title">出票银行</td>
            <td class="td-value">
                <input v-model="jsonData.drawerBank" style="width: 100%;border: none" />
            </td>
            <td class="td-title">收入项目</td>
            <td class="td-value">
                <input v-model="jsonData.incomeProject" style="width: 100%;border: none" />
            </td>
        </tr>
        <tr>
            <td class="td-title">出票日期</td>
            <td class="td-value">
                <input type="text" v-model="jsonData.drawerDate" @focus="showDatePicker($event,'','drawerDate')" style="width: 100%;border: none;background: url(../../../dist/img/date.png) no-repeat right;">
            </td>
            <td class="td-title">到期日期</td>
            <td class="td-value">
                <input type="text" v-model="jsonData.dueDate" @focus="showDatePicker($event,'','dueDate')" style="width: 100%;border: none;background: url(../../../dist/img/date.png) no-repeat right;">
            </td>
            <td class="td-title">汇票号码</td>
            <td class="td-value">
                <input v-model="jsonData.debitsNo" style="width: 100%;border: none" />
            </td>
        </tr>
        <tr>
            <td class="td-title">金额</td>
            <td class="td-value">
                <input v-model="jsonData.money" style="width: 100%;border: none" />
            </td>
            <td class="td-title">收票日期</td>
            <td class="td-value">
                <input type="text" v-model="jsonData.invoiceDate" @focus="showDatePicker($event,'','invoiceDate')" style="width: 100%;border: none;background: url(../../../dist/img/date.png) no-repeat right;">
            </td>
            <td class="td-title">是否背书</td>
            <td class="td-value">
                <select v-model="jsonData.endorseFlag" @change="changeEndorseFlag" style="width: 100%;float: left;border: none;background: none">
                    <option value="0" selected>否</option>
                    <option value="1">是</option>
                </select>
            </td>
        </tr>
        <tr v-if="jsonData.endorseFlag==1">
            <td class="td-title">背书方式</td>
            <td colspan="5" class="td-value">
                <select  v-model="jsonData.endorseMode" style="width: 100%; float: left; border: none; background: none;">
                    <option value="0">托收</option>
                    <option value="1">贴现</option>
                    <option value="2">转出</option>
                </select>
            </td>
        </tr>
        <template v-if="jsonData.endorseFlag==1 && jsonData.endorseMode==0">
            <tr>
                <td class="td-title">托收银行</td>
                <td class="td-value">
                    <select v-model="collection.fkBankCardId" style="width: 230px;float: left;border: none;background: none">
                        <template v-for="(bank,index) in bankList">
                            <option :value="bank.id" v-if="bank.id==collection.fkBankCardId" selected>{{bank.bankName}}</option>
                            <option :value="bank.id" v-else>{{bank.bankName}}</option>
                        </template>
                    </select>

                </td>
                <td class="td-title">背书日期</td>
                <td class="td-value">
                    <input type="text" v-model="collection.endorseDate" @focus="showDatePicker($event,'collection','endorseDate')" style="width: 100%;border: none;background: url(../../../dist/img/date.png) no-repeat right;">
                </td>
                <td class="td-title">托收是否到账</td>
                <td class="td-value">
                    <select @change="changeCollectionArriveFlag" v-model="collection.collectionArriveFlag" style="width: 100%;float: left;border: none;background: none">
                        <option value="0" selected>否</option>
                        <option value="1">是</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="td-title">到账日期</td>
                <td class="td-value">
                    <input type="text" v-model="collection.collectionArriveDate" @focus="showDatePicker($event,'collection','collectionArriveDate')" style="width: 100%;border: none;background: url(../../../dist/img/date.png) no-repeat right;">
                </td>
                <td class="td-title">是否质押</td>
                <td class="td-value">
                    <select v-model="collection.impawnFLAg" style="width: 100%;float: left;border: none;background: none">
                        <option value="0" selected>否</option>
                        <option value="1">是</option>
                    </select>
                </td>
                <td class="td-title">备注</td>
                <td class="td-value">
                    <input v-model="collection.remark" style="width: 100%;border: none" />
                </td>
            </tr>
            <tr>
                <td class="td-title">支出项目</td>
                <td colspan="5" class="td-value">
                    <input v-model="collection.outcomeProject" style="width: 100%;border: none" />
                </td>
            </tr>
        </template>

        <template v-if="jsonData.endorseFlag==1 && jsonData.endorseMode==1">
            <tr>
                <td class="td-title">贴现银行</td>
                <td class="td-value">
                    <input v-model="discount.discountBank" style="width: 100%;border: none" />
                </td>
                <td class="td-title">贴现日期</td>
                <td class="td-value">
                    <input type="text" v-model="discount.discountDate" @focus="showDatePicker($event,'discount','discountDate')" style="width: 100%;border: none;background: url(../../../dist/img/date.png) no-repeat right;">
                </td>
                <td class="td-title">贴现息</td>
                <td class="td-value">
                    <input v-model="discount.discountInterest" style="width: 100%;border: none" />
                </td>
            </tr>
            <tr>
                <td class="td-title">贴现金额</td>
                <td class="td-value">
                    <input v-model="discount.discountMoney" style="width: 100%;border: none" />
                </td>
                <td class="td-title">是否质押</td>
                <td class="td-value">
                    <select v-model="discount.impawnFLAg" style="width: 100%;float: left;border: none;background: none">
                        <option value="0" selected>否</option>
                        <option value="1">是</option>
                    </select>
                </td>
                <td class="td-title">备注</td>
                <td class="td-value">
                    <input v-model="discount.remark" style="width: 100%;border: none" />
                </td>
            </tr>
            <tr>
                <td class="td-title">支出项目</td>
                <td colspan="5" class="td-value">
                    <input v-model="discount.outcomeProject" style="width: 100%;border: none" />
                </td>
            </tr>
        </template>

        <template v-if="jsonData.endorseFlag==1 && jsonData.endorseMode==2">
            <tr>
                <td class="td-title">客户名称</td>
                <td class="td-value">
                    <input v-model="turnOut.customerName" style="width: 100%;border: none" />
                </td>
                <td class="td-title">背书日期</td>
                <td class="td-value">
                    <input type="text" v-model="turnOut.endorseDate" @focus="showDatePicker($event,'turnOut','endorseDate')" style="width: 100%;border: none;background: url(../../../dist/img/date.png) no-repeat right;">
                </td>
                <td class="td-title">是否质押</td>
                <td class="td-value">
                    <select v-model="turnOut.impawnFLAg" style="width: 100%;float: left;border: none;background: none">
                        <option value="0" selected>否</option>
                        <option value="1">是</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="td-title">备注</td>
                <td class="td-value">
                    <input v-model="turnOut.remark" style="width: 100%;border: none" />
                </td>
                <td class="td-title">支出项目</td>
                <td colspan="3" class="td-value">
                    <input v-model="turnOut.outcomeProject" style="width: 100%;border: none" />
                </td>
            </tr>
        </template>

        </tbody>
    </table>

    <div style="height:30px;line-height:30px;text-align: center;z-index:999;padding-top:5px;margin-bottom: 15px">
        <input type="button" value="保存" @click="save()" class="btn oaBtn btn-sm" style="margin-top:5px;">
    </div>
    </div>
    <!-- /.box-body -->
</section>
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=8e743a31"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=54c6b89c"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script type="text/javascript" src="/dist/plugins/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript" src="/dist/plugins/select2/select2.full.min.js"></script>
<script type="text/javascript">
    Vue.directive('select2', {
        inserted: function (el, binding, vnode) {
            var options = binding.value || {};

            $(el).select2(options).on("select2:select", function (e) {
                el.dispatchEvent(new Event('change', {target: e.target})); //说好的双向绑定，竟然不安套路
            });
        },
        update: function (el, binding, vnode) {
            $(el).trigger("change");
        }
    });
    var app = new Vue({
        el: '#list',
        data: {
            jsonData:{
                drawerName:"",      //  出票人
                drawerBank:"",      //  出票银行
                incomeProject:"",   //  收入项目
                drawerDate:"",      //  出票日期
                dueDate:"",         //  到期日期
                debitsNo:"",        //  汇票号码
                money:"",           //  金额
                invoiceDate:new Date().Format("yyyy-MM-dd"),//  收票日期
                endorseFlag:"0",    //  是否背书
                endorseMode:"",     //  背书方式
                createUserId:getCurrentUser().id,
                updateUserId:"",
                updateTime:"",
                fkCompanyId:getCurrentUser().companyId,
                delFlag:'0'
            },
            collection:{//  托收
                fkBankCardId:"",        //  托收银行
                endorseDate:new Date().Format("yyyy-MM-dd"),         //  背书日期
                collectionArriveFlag:"0",//  托收是否到账
                collectionArriveDate:"",//  到账日期
                impawnFLAg:"0",          //  是否质押
                remark:"",              //  备注
                outcomeProject:""       //  支出项目
            },
            discount:{  //  贴现
                discountBank:"",    //  贴现银行
                discountDate:new Date().Format("yyyy-MM-dd"),    //  贴现日期
                discountInterest:"",//  贴现息
                discountMoney:"",   //  贴现金额
                impawnFLAg:"0",      //  是否质押
                remark:"",          //  备注
                outcomeProject:""   //  支出项目
            },
            turnOut:{
                customerName:"",    //  客户姓名
                endorseDate:new Date().Format("yyyy-MM-dd"),     //  背书日期
                impawnFLAg:"0",      //  是否质押
                remark:"",          //  备注
                outcomeProject:""   //  支出项目
            },
            time:"",
            bankList:[]
        },
        methods: {
            changeCollectionArriveFlag:function () {
                if (this.collection.collectionArriveFlag=="1"){
                    this.collection.collectionArriveDate=new Date().Format("yyyy-MM-dd");
                }else {
                    this.collection.collectionArriveDate="";
                }
            },
            changeEndorseFlag:function () {
                var that = this;
                if (that.jsonData.endorseFlag="1"){
                    that.jsonData.endorseMode="0"
                }else {
                    that.jsonData.endorseMode=""
                }
            },
            save:function () {

                if (this.jsonData.endorseFlag == 1 && this.jsonData.endorseMode == 0 && this.collection.collectionArriveFlag==1 && this.collection.collectionArriveDate.length==0){
                    alert("请填写到账日期");
                    return;
                }
                if (this.jsonData.drawerName.length==0){
                    alert("请填写出票人");
                    return;
                }else if (this.jsonData.drawerBank.length==0){
                    alert("请填写出票银行");
                    return;
                }else if (this.jsonData.incomeProject.length==0){
                    alert("请填写收入项目");
                    return;
                }else if (this.jsonData.drawerDate.length==0){
                    alert("请填写出票日期");
                    return;
                }else if (this.jsonData.dueDate.length==0){
                    alert("请填写到期日期");
                    return;
                }else if (this.jsonData.debitsNo.length==0){
                    alert("请填写汇票号码");
                    return;
                }else if (this.jsonData.money.length==0){
                    alert("请填写金额");
                    return;
                }else if (this.jsonData.invoiceDate.length==0){
                    alert("请填写收票日期");
                    return;
                }
                var json = {};
                if (this.jsonData.endorseFlag=="0"){
                    json = this.jsonData;
                }else if(this.jsonData.endorseMode=="0"){
                    json = Object.assign(this.jsonData,this.collection);
                }else if(this.jsonData.endorseMode=="1"){
                    json = Object.assign(this.jsonData,this.discount);
                }else if(this.jsonData.endorseMode=="2"){
                    json = Object.assign(this.jsonData,this.turnOut);
                }
                $.wyui.postMethod('/bankDebitsFacade/save.json', trimRN(json), function (data) {
                    alert("操作成功");
                    parent.refresh();
                    var api = frameElement.api, W = api.opener;
                    api.close();
                });
            },
            showDatePicker: function (e,firstType,type) {
                var that = this;
                WdatePicker({
                    onpicked: function (dp) {
                        if (firstType.length==0){
                            that.jsonData[type] = dp.cal.getNewDateStr();
                        }else {
                            that.jsonData[firstType][type] = dp.cal.getNewDateStr();
                        }
                        return true;
                    },
                });
                $(e.target).blur();
            }
        },

        mounted: function () {
            var that=this;
            $.wyui.postMethod('/bankCard/getBankCardList.json', {fkCompanyId:getCurrentUser().companyId,useStatus:1}, function (data) {
                console.log(data);
                that.bankList=data;
                that.collection.fkBankCardId=that.bankList[0].id;
            });
            }
    });


</script>

</body>
</html>